<template>
  <div class="min-h-screen bg-gray-50 flex items-center justify-center p-6">
    <div class="bg-white rounded-2xl shadow-sm w-full max-w-xl p-8">
      <h1 class="text-2xl font-bold text-gray-900 mb-2">短信验证</h1>
      <p class="text-gray-600 mb-8">通过绑定手机接收验证码完成管理员验证</p>

      <div class="mb-6">
        <label class="block text-sm font-medium text-gray-700 mb-2">手机号码</label>
        <input v-model="phone" type="tel" placeholder="请输入管理员手机号" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" />
      </div>

      <div class="mb-6">
        <label class="block text-sm font-medium text-gray-700 mb-2">验证码</label>
        <div class="flex gap-3">
          <input v-model="code" type="text" placeholder="请输入验证码" class="flex-1 px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" />
          <button class="px-4 py-3 bg-white border-2 border-blue-600 text-blue-600 rounded-lg font-medium hover:bg-blue-50 transition-colors whitespace-nowrap" @click="sendCode" :disabled="countdown>0">{{ countdown>0 ? countdown+'s后重发' : '获取验证码' }}</button>
        </div>
      </div>

      <div class="flex items-center justify-between">
        <button class="px-4 py-2 text-gray-600 hover:text-gray-900" @click="$router.push('/admin/login')">返回</button>
        <button class="px-6 py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-lg font-medium" @click="completeVerify">完成验证</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AdminVerifySMS',
  data() {
    return { phone: '', code: '', countdown: 0 }
  },
  methods: {
    sendCode() {
      if (!this.phone) { alert('请输入手机号'); return }
      if (this.countdown > 0) return
      this.countdown = 60
      const t = setInterval(() => { this.countdown--; if (this.countdown <= 0) clearInterval(t) }, 1000)
    },
    completeVerify() {
      if (!this.code || this.code.length < 4) { alert('请输入有效验证码'); return }
      localStorage.setItem('adminToken', 'verified')
      localStorage.setItem('adminInfo', JSON.stringify({ role: 'admin', verifiedAt: Date.now() }))
      this.$router.push('/admin/dashboard')
    }
  }
}
</script>


